using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Xml;
using System.Web.UI;
using System.Web.UI.WebControls;
 

public partial class DeletePage : System.Web.UI.Page
{
    string fileName = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        fileName = Server.MapPath("Books.xml");
        if (!IsPostBack)
            ShowNodes(fileName, "book");
    }
    bool DeleteNode(XmlDocument xmlDocument,
    string xmlNodeName, string xmlNodeValue)
    {
        bool foundNode = false;
        XmlNodeList xmlNodeList =
        xmlDocument.GetElementsByTagName("book");
        foreach (XmlNode xmlNode in xmlNodeList)
        {
            if (xmlNode.Attributes[xmlNodeName].Value
            == xmlNodeValue)
            {
                foundNode = true;
                 
                xmlDocument.DocumentElement.RemoveChild(xmlNode);
                break;
            }
        }
       
        return foundNode;
    }
    void ShowNodes(string fileName, string nodeName)
    {
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(fileName);

        XmlNodeList xmlNodeList =
        xmlDocument.GetElementsByTagName(nodeName);
        Table table = new Table();
        foreach (XmlNode xmlNode in xmlNodeList)
        {

            TableRow tableRow = new TableRow();
            TableCell tableCell = new TableCell();
            tableCell.Text = "ISBN";
            tableCell = new TableCell();

            tableCell.Wrap = false;
            tableCell.Text =
            xmlNode.Attributes["ISBN"].Value;
            tableRow.Cells.Add(tableCell);

            foreach (XmlElement xmlElement in
            xmlNode.ChildNodes)
            {
                tableCell = new TableCell();
                tableCell.Wrap = false;
                tableCell.Text = xmlElement.InnerText;
                tableRow.Cells.Add(tableCell);
            }
            table.Rows.Add(tableRow);

        }

        PlaceHolder1.Controls.Add(table);

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(fileName);

        if (DeleteNode(xmlDocument, "ISBN", txtISBN.Text))
            xmlDocument.Save(fileName);
        ShowNodes(fileName, "book");
    }
}
